import { resolvePkgPath, getPackageJSON, getBaseRollupPlugins } from './utils';
import generatePackageJson from 'rollup-plugin-generate-package-json';
import path from 'path';

const { name, module } = getPackageJSON('react');

const pkgPath = resolvePkgPath(name);

const pkgDistPath = resolvePkgPath(name, true);

// 调试的输出目录
const devPath = path.resolve(__dirname, '../../react-demo/src');

export default [
	{
		input: `${pkgPath}/${module}`,
		output: {
			file: `${pkgDistPath}/index.js`,
			// file: `${devPath}/react/index.js`,
			name: 'React',
			format: 'umd' // 兼容esm和commonjs
		},
		plugins: [
			...getBaseRollupPlugins(),
			generatePackageJson({
				inputFolder: pkgPath,
				outputFolder: pkgDistPath,
				baseContents: ({ name, description, version }) => ({
					// 只生产这些字段
					name,
					description,
					version,
					main: 'index.js' // 因为是 umd 格式，所以需要指定 main
				})
			})
		]
	},
	{
		input: `${pkgPath}/src/jsx.ts`,
		output: [
			{
				file: `${pkgDistPath}/jsx-runtime.js`,
				// file: `${devPath}/react/jsx-runtime.js`,
				name: 'jsx-runtime',
				format: 'esm'
			},
			{
				file: `${pkgDistPath}/jsx-dev-runtime.js`,
				// file: `${devPath}/react/jsx-dev-runtime.js`,
				name: 'jsx-dev-runtime',
				format: 'umd'
			}
		],
		plugins: getBaseRollupPlugins()
	}
];
